/***************************************************************************
 *  Filename: GPSData.cpp
 *  Class: GPSData
 *
 *  Copyright 2012  Jacco van der Spek
 *  <jaccovdspek@gmail.com>
 *
 *  Copyright 2012  Mario Henrique Voorsluys
 *  <forcaeluz@gmail.com>
 *
 ****************************************************************************/

/*
 *
 * This file is part of %ProjectName%.
 *
 *    %ProjectName% is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    %ProjectName% is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with %ProjectName%.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "gpsdata.h"
#include <QDebug>
GPSData::GPSData()
{
    lat =0;
    lng =0;
    alt =0;
    vel  =0;
    bear = 0;
    ns = 'N';
    ew = 'E';
    status = 'A';
}


// Setters
void GPSData::setLatitude(float lat){
    qDebug() << "[GPSData] Setting Latitude" << lat;
    if(lat >= 0){
        this->lat = lat;
        setNS('N');
    }else{
        this->lat = -lat;
        setNS('S');
    }
}

void GPSData::setLongitude(float lng){
    qDebug() << "[GPSData] Setting Longitude" << lng;
    if(lat >= 0){
        this->lng = lng;
        setEW('E');
    }else{
        this->lng = -lng;
        setEW('W');
    }
}

void GPSData::setVelocity(float vel){
    this->vel = vel;
}

void GPSData::setNS(QChar ns){
    qDebug() << "[GPSData] Setting NS to: " << ns;
    this->ns = ns;
}

void GPSData::setEW(QChar ew){
    this->ew = ew;
}

void GPSData::setStatus(QChar status){
    this->status = status;
}

void GPSData::setBearing(float bear)
{
    this->bear=bear;
}


// Getters
float GPSData::getLatitude()
{
    float lati = 0;
    if(ns == 'N')
    {
        lati = lat;
    }
    else if(ns == 'S')
    {
        lati = -lat;
    }
    else
    {
        qWarning() << "[GPSData] North/South Undefined";
    }
    return lati;
}

float GPSData::getLongitude()
{
    float longi = 0;
    if(ew == 'E')
    {
        longi = lng;
    }
    else if (ew == 'W')
    {
        longi = -lng;
    }
    else
    {
        qWarning() << "East/West Undefined";
    }
    return longi;
}

float GPSData::getVelocity()
{
    return vel;
}

QChar GPSData::getStatus()
{
    return status;
}

float GPSData::getBearing()
{
    return bear;
}

GPSData GPSData::getTargetCoordinates(float distancex, float distancey){
    //FIX-ME: Dumb function that only copies the target location.
    Q_UNUSED(distancex);
    Q_UNUSED(distancey);
    GPSData tmp;
    tmp.setLatitude(lat);
    tmp.setLongitude(lng);
    return tmp;
}
